<?php
require_once (APPPATH.'views/components/page.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<link href='<?php echo base_url() ?>resources/css/admin.css' rel='stylesheet' type='text/css' />
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		<title>Administrator</title>
		<?php
			$newpasserror = form_error('newpassword');
			$confpasserror = form_error('confirmpassword');
			$userdata = NULL;
			$page = Page::getInstance();
		?>
	</head>
	
	<body>
		<div id='wrapper'>
			<div id='header'>
				<div id="leftTopPan">
				<a href='<?php echo base_url() ?>'><img src='<?php echo base_url() ?>resources/images/logo.gif' title='Consultant' alt='Consultant' width='160' height='39' border='0' /></a>
				</div>
				<h1></h1>
			</div>
			<div id="middle">
				<div id="container">
					<div id="content">
					<?php
					$error = $this->session->userdata('error');
					$this->session->unset_userdata('error');
					
					if (isset($rerror))
					$error = $rerror;
					
					// Password change required, show change password form here
					if ($error == PASSWORD_CHANGE_REQUIRED)
					{
						
					?>
					<p>Đây là lần đầu tiên đăng nhập vào trang admin, vui lòng đổi mật khẩu</p></br>
					<?php
						$newPassword = array('name'		=> 'newpassword',
											'id'		=> 'newpassword',
											'maxlength'	=> '50',
											'type'		=> 'password');
						$confirmPassword = array('name'		=> 'confirmpassword',
											'id'			=> 'confirmpassword',
											'maxlength'		=> '50',
											'type'			=> 'password');
											
						echo form_open('admin/changepassword');
					?>
						Mật khẩu mới: <?php echo form_input($newPassword) ?> (A-Z, a-z, 0-9) <?php echo $newpasserror ?></br>
						Nhập lại mật khẩu: <?php echo form_input($confirmPassword);
												echo $confpasserror ?></br>
						<?php echo form_hidden('username', isset($username) ? $username : "") ?>
						<?php echo form_submit('save', 'Lưu') ?>
					
					<?php
						echo form_close();
					}
					elseif ($error == AUTHORIZE_FAILED || $error == UNAUTHORIZED_ERROR)
					{
						$username = array('name'	=> 'username',
										'id'		=> 'username',
										'value'		=> '',
										'maxlength'	=> '50');
						$password = array('name'	=> 'password',
										'id'		=> 'password',
										'type'		=> 'password',
										'maxlength'	=> '50');
										
						if ($error == AUTHORIZE_FAILED)
						{
					?>
							<h2 style="color: red">Sai Tên đăng nhập hoặc Mật khẩu</h2><br />
					<?php
						}
					?>
						<?php echo form_open('admin/login') ?>
						Tên đăng nhập: <?php echo form_input($username) ?><br>
						Mật khẩu: <?php echo form_input($password) ?>
						<?php echo form_submit('Login', 'Login') ?>
						<?php echo form_close() ?>
					<?php
					}
					else {
						$userdata = $this->session->userdata('userdata');
						if ($userdata != NULL)
						{
							$page->generateUserInfo($userdata);
						}
					}
					?>
					</div>
				</div>
					<?php
						if (Page::getInstance()->isAdmin())
						{
							Page::getInstance()->generateAdminLeftMenu();
						}
					?>
			</div>
		</div>
		
	</body>
</html>